//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __CHANNEL_MAGIC_H__
#define __CHANNEL_MAGIC_H__

#include "ChannelIO.h"

class ChannelMagic
{
public:
    static const unsigned char TYPE_SEND = 0x67;
    static const unsigned char TYPE_SUCCEED = 0x34;
    static const unsigned char TYPE_FAIL = 0x52;

private:

public:
    ChannelMagic();
    ChannelMagic(unsigned char number);
    virtual ~ChannelMagic();

    void WriteBuffer(char* buffer);
    int Write(WriteOutputStream os);
    int Read(ReadInputStream is);

    inline unsigned char GetNumber() const
    {
        return m_number;
    }
    inline void SetNumber(unsigned char number)
    {
        m_number = number;
    }

private:
    void DispatchRawData(void *data, int size);
    bool IsValidMagicNumber(char* header);

private:
    unsigned char m_number;
};

#endif //__CHANNEL_MAGIC_H__
